﻿using System;
using System.Data;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Token.Piker.DAL;
using  Token.Piker.Model;

namespace Token.Piker.Core.Album
{
    public class AlbumProxy
    {
        public static List< Token.Piker.Model.Album> GetAlbumList(string where)
        {
            AlbumDAL dao = new AlbumDAL();
            DataTable dt = dao.GetList(where).Tables[0];
            List< Token.Piker.Model.Album> modelList = new List< Token.Piker.Model.Album>();
            int rowsCount = dt.Rows.Count;
            if (rowsCount > 0)
            {
                 Token.Piker.Model.Album model;
                for (int n = 0; n < rowsCount; n++)
                {
                    model = new  Token.Piker.Model.Album();
                    if (dt.Rows[n]["ID"] != null && dt.Rows[n]["ID"].ToString() != "")
                    {
                        model.ID = int.Parse(dt.Rows[n]["ID"].ToString());
                    }
                    if (dt.Rows[n]["AlbumName"] != null && dt.Rows[n]["AlbumName"].ToString() != "")
                    {
                        model.AlbumName = dt.Rows[n]["AlbumName"].ToString();
                    }
                    if (dt.Rows[n]["Descrip"] != null && dt.Rows[n]["Descrip"].ToString() != "")
                    {
                        model.Descrip = dt.Rows[n]["Descrip"].ToString();
                    }
                    if (dt.Rows[n]["CreateTime"] != null && dt.Rows[n]["CreateTime"].ToString() != "")
                    {
                        model.CreateTime = DateTime.Parse(dt.Rows[n]["CreateTime"].ToString());
                    }

                    modelList.Add(model);
                }
            }
            return modelList;
        }

        public static  Token.Piker.Model.Album GetInfoByID(string id)
        {
            AlbumDAL dao = new AlbumDAL();
            var model = dao.GetModel(Convert.ToInt32(id));
            return model;
        }

        public static int AddAlbum( Token.Piker.Model.Album album)
        {
            AlbumDAL dao = new AlbumDAL();
            return dao.Add(album);
        }

        //public static int AddPhotoAlbum(string aid, string pid)
        //{
        //    PhotoAlbumDAL dao = new PhotoAlbumDAL();
        //    PhotoAlbum model = new PhotoAlbum();
        //    model.AID = Convert.ToInt32(aid);
        //    model.PID = Convert.ToInt32(pid);
        //    return dao.Add(model);
        //}

        //public static int AddAlbumTag(string aid, string tagid)
        //{
        //    //AlbumDAL album_dao = new AlbumDAL();
        //    AlbumTagDAL tag_dao = new AlbumTagDAL();
        //    AlbumTag model = new AlbumTag();
        //    model.AID = Convert.ToInt32(aid);
        //    model.TID = Convert.ToInt32(tagid);
        //    return tag_dao.Add(model);
            
        //}

        public int Add_Relation_Photo(string aid, string pid)
        {
            return 0;
        }
        
    }
}
